﻿CREATE TRIGGER [tr_TrackerTransaction_Delete]
ON dbo.t_TrackerTransaction 
FOR UPDATE, DELETE
AS

IF @@ROWCOUNT = 0 RETURN
IF UPDATE (StatusID) RETURN

IF NOT EXISTS(SELECT * FROM deleted WHERE dbo.MenuAttribute_Locked(StatusID) = 1) RETURN

DECLARE @Status sysname 
SELECT    @Status = t_Menu.MenuName
FROM         deleted AS i INNER JOIN
                      t_Menu ON i.StatusID = t_Menu.MenuID
RAISERROR('Pay To Installer Transaction is locked due to it''s status[%s].',16,1,@Status)
ROLLBACK TRAN
